#include <vector>
#include <set>
#include <iostream>
#include <unordered_map>
using namespace std;

vector<vector<int>> imageSmoother(vector<vector<int>>& img) {
    vector<vector<int>> temp(img.size()+2, vector<int> (img[0].size()+2,-1));
    for(int i = 1; i <= img.size(); i++){
        for(int j = 1; j <= img[0].size(); j++){
           temp[i][j] = img[i-1][j-1];
        }
    }
    for(int i = 1; i <= img.size(); i++){
        for(int j = 1; j <= img[0].size(); j++){
            int num = 9, sum = 0;
            for(int ii = -1; ii < 2; ii++){
                for(int ij = -1; ij < 2; ij++){
                    if(temp[i+ii][j+ij] == -1){
                        num--;
                    }else{
                        sum += temp[i+ii][j+ij];
                    }
                }
            }
            img[i-1][j-1] = sum/num;
        }
    }
    return img;
}

int main(){
    vector<vector<int>> img = { {100,200,100},{200,50,200},{100,200,100} };
    vector<vector<int>> out = imageSmoother(img);
    for(int i = 0; i < out.size(); i++){
        for(int j = 0; j < out[0].size(); j++){
           cout << out[i][j] << endl;
        }
    }
    return 0;
}